package 可视化算法.排序算法可视化.选择排序算法可视化添加更多效果;

/**
 * @author MT
 * 排序数对象
 * @date 2019-11-29 11:25
 */
public class SelectionSortData {

        // 排序数组
        private int[] numbers;
        // [ 0 .... orderedIndex) 是有序的
        public  int orderedIndex  = -1;
        // 当前找到的最小元素的索引
        public int currentMinIndex = -1;
        // 当前正在比较的元素索引
        public int currentCompareIndex = -1;

    public SelectionSortData(int N, int randomBound){

            numbers = new int[N];

            for( int i = 0 ; i < N ; i ++)
                numbers[i] = (int)(Math.random()*randomBound) + 1;
        }

        public int N(){
            return numbers.length;
        }

        public int get(int index){
            if( index < 0 || index >= numbers.length){
                throw new IllegalArgumentException("Invalid index to access Sort Data.");
            }

            return numbers[index];
        }

    /**
     * 交换元素位置
     * @param i
     * @param j
     */
    public void swap(int i, int j) {

        if( i < 0 || i >= numbers.length || j < 0 || j >= numbers.length){
            throw new IllegalArgumentException("Invalid index to access Sort Data.");
        }

        int t = numbers[i];
        numbers[i] = numbers[j];
        numbers[j] = t;
    }
}
